package santiago.view.lobby;

import santiago.client.Client;
import santiago.domain.DifficultyLevel;
import santiago.view.SantiagoDialog;
import santiago.view.SantiagoValidation;

public class DialogCreateGame extends SantiagoDialog {

    /**
     * Creates new form DialogCreateGame
     */
    public DialogCreateGame(java.awt.Frame Parent, boolean Modal) {
        super(Parent, Modal);
        initComponents();
        setLocationRelativeTo(null);
    }

    @Override
    public void refresh() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LabelGameName = new javax.swing.JLabel();
        LabelDifficultyLevel = new javax.swing.JLabel();
        LabelPalmTree = new javax.swing.JLabel();
        TextFieldGameName = new javax.swing.JTextField();
        ButtonCreateGame = new javax.swing.JButton();
        ButtonCancel = new javax.swing.JButton();
        SpinnerPlayersNumber = new javax.swing.JSpinner();
        CheckBoxDisplayCash = new javax.swing.JCheckBox();
        LabelDisplayCash = new javax.swing.JLabel();
        CheckBoxPalmTree = new javax.swing.JCheckBox();
        LabelPlayersNumber = new javax.swing.JLabel();
        ComboBoxDifficultyLevel = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Créer une partie");
        setResizable(false);

        LabelGameName.setFont(new java.awt.Font("Lucida Sans", 1, 14)); // NOI18N
        LabelGameName.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        LabelGameName.setText("Nom de la partie");

        LabelDifficultyLevel.setFont(new java.awt.Font("Lucida Sans", 1, 14)); // NOI18N
        LabelDifficultyLevel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        LabelDifficultyLevel.setText("Difficulté");

        LabelPalmTree.setFont(new java.awt.Font("Lucida Sans", 1, 14)); // NOI18N
        LabelPalmTree.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        LabelPalmTree.setText("Palmiers");

        TextFieldGameName.setFont(new java.awt.Font("Lucida Sans", 0, 14)); // NOI18N
        TextFieldGameName.setName(""); // NOI18N

        ButtonCreateGame.setFont(new java.awt.Font("Lucida Sans", 1, 14)); // NOI18N
        ButtonCreateGame.setForeground(new java.awt.Color(179, 96, 74));
        ButtonCreateGame.setText("Créer la partie");
        ButtonCreateGame.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonCreateGameActionPerformed(evt);
            }
        });

        ButtonCancel.setFont(new java.awt.Font("Lucida Sans", 1, 14)); // NOI18N
        ButtonCancel.setForeground(new java.awt.Color(179, 96, 74));
        ButtonCancel.setText("Annuler");
        ButtonCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonCancelActionPerformed(evt);
            }
        });

        SpinnerPlayersNumber.setFont(new java.awt.Font("Lucida Sans", 0, 14)); // NOI18N
        SpinnerPlayersNumber.setModel(new javax.swing.SpinnerNumberModel(3, 3, 5, 1));
        SpinnerPlayersNumber.setPreferredSize(new java.awt.Dimension(40, 23));

        CheckBoxDisplayCash.setFont(new java.awt.Font("Lucida Sans", 0, 14)); // NOI18N
        CheckBoxDisplayCash.setSelected(true);
        CheckBoxDisplayCash.setText("oui");

        LabelDisplayCash.setFont(new java.awt.Font("Lucida Sans", 1, 14)); // NOI18N
        LabelDisplayCash.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        LabelDisplayCash.setText("Argent visible");

        CheckBoxPalmTree.setFont(new java.awt.Font("Lucida Sans", 0, 14)); // NOI18N
        CheckBoxPalmTree.setText("oui");

        LabelPlayersNumber.setFont(new java.awt.Font("Lucida Sans", 1, 14)); // NOI18N
        LabelPlayersNumber.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        LabelPlayersNumber.setText("Nombre de joueur");

        ComboBoxDifficultyLevel.setFont(new java.awt.Font("Lucida Sans", 0, 14)); // NOI18N
        ComboBoxDifficultyLevel.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Facile", "Moyen", "Difficile", "Impossible" }));

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(LabelGameName))
                    .add(layout.createSequentialGroup()
                        .add(21, 21, 21)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(LabelDisplayCash)
                            .add(LabelPalmTree)
                            .add(LabelDifficultyLevel))
                        .add(46, 46, 46)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(ButtonCreateGame)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(ButtonCancel))
                            .add(ComboBoxDifficultyLevel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 232, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(CheckBoxDisplayCash)
                            .add(CheckBoxPalmTree))))
                .add(21, 21, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(LabelPlayersNumber)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(SpinnerPlayersNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(TextFieldGameName)
                        .add(21, 21, 21))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(28, 28, 28)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(LabelGameName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(TextFieldGameName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(17, 17, 17)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(LabelPlayersNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(SpinnerPlayersNumber, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(17, 17, 17)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(LabelDifficultyLevel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(ComboBoxDifficultyLevel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(14, 14, 14)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(CheckBoxDisplayCash)
                    .add(LabelDisplayCash, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(13, 13, 13)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(LabelPalmTree, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(CheckBoxPalmTree))
                .add(30, 30, 30)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(ButtonCreateGame)
                    .add(ButtonCancel))
                .addContainerGap(28, Short.MAX_VALUE))
        );

        setSize(new java.awt.Dimension(437, 329));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void ButtonCreateGameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonCreateGameActionPerformed
        if (SantiagoValidation.checkEmptyField(TextFieldGameName.getText())) {
            DifficultyLevel Level;
            switch ((String) ComboBoxDifficultyLevel.getSelectedItem()) {
                case "Facile":
                    Level = DifficultyLevel.Easy;
                    break;
                case "Moyen":
                    Level = DifficultyLevel.Medium;
                    break;
                case "Difficile":
                    Level = DifficultyLevel.Hard;
                    break;
                case "Impossible":
                    Level = DifficultyLevel.Impossible;
                    break;
                default:
                    Level = DifficultyLevel.Easy;
            }
            Client.createGame(TextFieldGameName.getText(), (Integer) SpinnerPlayersNumber.getValue(), Level, CheckBoxDisplayCash.isSelected(), CheckBoxPalmTree.isSelected());
        }
    }//GEN-LAST:event_ButtonCreateGameActionPerformed

    private void ButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonCancelActionPerformed
        Client.getInterface().closeDialog();
    }//GEN-LAST:event_ButtonCancelActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonCancel;
    private javax.swing.JButton ButtonCreateGame;
    private javax.swing.JCheckBox CheckBoxDisplayCash;
    private javax.swing.JCheckBox CheckBoxPalmTree;
    private javax.swing.JComboBox ComboBoxDifficultyLevel;
    private javax.swing.JLabel LabelDifficultyLevel;
    private javax.swing.JLabel LabelDisplayCash;
    private javax.swing.JLabel LabelGameName;
    private javax.swing.JLabel LabelPalmTree;
    private javax.swing.JLabel LabelPlayersNumber;
    private javax.swing.JSpinner SpinnerPlayersNumber;
    private javax.swing.JTextField TextFieldGameName;
    // End of variables declaration//GEN-END:variables
}
